/**
 * Captain
 * © 2017 Captain copyright，All rights reserved.
 * http://www.sccaptain.com.cn
 * <p>
 * JAVA : 8
 * 文  件  名: LastUpdateListener.java
 * 创  建  人: liujian (liu.jian@sccaptain.com.cn)
 * 创建时间: 2017/12/1 9:44
 * 版         本: 1.0.0
 * 备         注:
 * 修订历史:
 */

package com.material.c2c.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.lang.reflect.Method;
import java.util.Date;

/**
 * 实体更新、保存监听，设置最后修改时间
 *
 * @since 1.0
 * @version 1.0
 * @author liujian (liu.jian@sccaptain.com.cn)
 */
public class LastUpdateListener {

  private static final String METHOD_NAME = "setZhxgsj";

  private Logger logger = LoggerFactory.getLogger(getClass());

  @PreUpdate
  @PrePersist
  public void setLastUpdate(Object entity) {
    try {
      Method method = entity.getClass().getMethod(METHOD_NAME, Date.class);
      method.invoke(entity, new Date());
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }
  }

}
